#!/bin/bash

# 设置默认设备名和挂载目录
default_device="/dev/sda"
default_mount_point="/opt/mnt"

# 提示用户输入要分区的设备名
read -p "Enter the device name (default: $default_device): " device_name
device_name=${device_name:-$default_device}

# 创建分区
fdisk $device_name <<EOF
n
p
1


w
EOF

# 格式化分区
mkfs.ext4 ${device_name}1

# 提示用户输入要挂载的目录
read -p "Enter the mount point (default: $default_mount_point): " mount_point
mount_point=${mount_point:-$default_mount_point}

# 创建挂载点
mkdir -p $mount_point

# 挂载分区
mount ${device_name}1 $mount_point

# 修改 /etc/fstab 文件，使分区开机自动挂载
echo "${device_name}1 $mount_point ext4 defaults 0 0" >> /etc/fstab


